package main

import (
	"fmt"
	"github.com/spf13/viper"
	"go.uber.org/zap"
	"goScaffold/dao"
	"goScaffold/logger"
	"goScaffold/routers"
	"goScaffold/settings"
)

func main() {
	//1、加载配置文件
	if err := settings.Init(); err != nil {
		fmt.Printf("加载文件出错，err:%v\n", err)
	}

	//2、初始化日志
	if err := logger.Init(settings.Config.LogConfig); err != nil {
		fmt.Printf("初始化日志出错，err:%v\n", err)
	}

	defer zap.L().Sync()

	//3、初始化MySQL
	if err := dao.InitDatabase(settings.Config.MysqlConfig); err != nil {
		fmt.Printf("初始化数据库出错，err:%v\n", err)
	}
	defer dao.CloseLinkedDatabase()
	//4、初始化Redis(暂时略)

	//5、注册Gin路由
	r := routers.SetupRouter()

	//6、启动
	r.Run(viper.GetString("app.port"))

	//6、启动服务（优雅关机）
}
